package com.renting.common.entity;

import com.alibaba.fastjson.JSONObject;
import com.renting.common.utils.StatusConstant;

import java.util.List;

/*
 * 规范返回代码格式
 */
public class Result {
    private Integer status = 0;
    private String msg = "";
    private Integer length;

    public Result() {

    }


    public Integer getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public Result(int status) {
        this.status = status;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setMsg(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }


    public String toJSONString() {
        return JSONObject.toJSONString(this);
    }

    /*
         * 成功信息
         */
    public static String successInfo(String msg, String data) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success", true);
        jsonObject.put("msg", msg);
        jsonObject.put("status", StatusConstant.SUCCESS);
        jsonObject.put("data", data);
        return jsonObject.toString();
    }

    /*
     * 失败信息
     */
    public static String errorInfo(String msg, String data) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success", false);
        jsonObject.put("msg", msg);
        jsonObject.put("status", StatusConstant.ERROR);
        jsonObject.put("data", data);
        return jsonObject.toString();
    }


}